package com.educatioin.manage.wechat.config;

import com.educatioin.manage.constant.WeChatApiConstant;
import com.github.wxpay.sdk.WXPayConfig;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

public class WXPayConfigImpl implements WXPayConfig {

    private byte[] certData;
    private static WXPayConfigImpl INSTANCE;

    private WXPayConfigImpl() throws Exception{
        InputStream certStream= this.getClass().getClassLoader().getResourceAsStream("apiclient_cert.p12");
        this.certData = new byte[certStream.available()];
        certStream.read(this.certData);
        certStream.close();
    }

    public static WXPayConfigImpl getInstance() throws Exception{
        if (INSTANCE == null) {
            synchronized (WXPayConfigImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WXPayConfigImpl();
                }
            }
        }
        return INSTANCE;
    }

    public String getAppID() {
        return WeChatApiConstant.APP_ID;
    }

    public String getMchID() {
        return WeChatApiConstant.MCH_ID;
    }

    public String getKey() {
        return "rosseduinf1234567890abcdefghijkl";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }


    public int getHttpConnectTimeoutMs() {
        return 2000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

}
